package com.gym.emp.web.controller;

import com.github.pagehelper.PageInfo;
import com.gym.emp.entity.Emp;
import com.gym.emp.services.EmpServices;
import com.gym.emp.services.impl.EmpServicesImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ming
 * 2021/11/10
 * description:分页设置
 */
@WebServlet("/getPage")
public class EmpController extends HttpServlet {

    private EmpServices es = new EmpServicesImpl();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageIndex = request.getParameter("pageIndex");
        //超出页码时
        if (pageIndex==null||pageIndex.equals("")) {
            pageIndex="1";
        }
        PageInfo<Emp> empByPages = es.getEmpByPages(Integer.valueOf(pageIndex));
        request.setAttribute("empInfo",empByPages);
        request.getRequestDispatcher("index.jsp").forward(request, response);
    }


}
